package com.zhyl.demo.service.impl;

import com.zhyl.demo.entity.Doctor;
import com.zhyl.demo.mapper.DoctorMapper;
import com.zhyl.demo.mapper.UserMapper;
import com.zhyl.demo.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author yang3
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    private final DoctorMapper doctorMapper;
    private final UserMapper userMapper;

    @Autowired
    private DoctorServiceImpl(DoctorMapper doctorMapper, UserMapper userMapper){
        this.doctorMapper = doctorMapper;
        this.userMapper = userMapper;
    }

    @Override
    public Doctor docInfo(Integer docId) {
        Doctor doctor = doctorMapper.docInfo(docId);
        if (doctor!=null){
            return doctor;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Doctor> docList(String specialty) {
        ArrayList<Doctor> doctors = doctorMapper.docList(specialty);
        if (doctors!=null){
            return doctors;
        }else{
            return null;
        }
    }

    @Override
    public Doctor getDoc(Integer userDoc) {
        Doctor doc = doctorMapper.getDoc(userDoc);
        if (doc!=null)
        {
            return doc;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Doctor> getAllDoc() {
        ArrayList<Doctor> allDoc = doctorMapper.getAllDoc();
        if (allDoc!=null){
            return allDoc;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Doctor> selectBySpecialty(String sname) {
        return doctorMapper.selectBySpecialty(sname);
    }

    @Override
    public boolean updateDocInfo(Doctor doctor) {
        int i = doctorMapper.updateDocInfo(doctor);
        return i>=0;
    }

    @Override
    public boolean deleteDoc(Integer id) {
        Integer i = doctorMapper.deleteDoc(id);
        return i>=0;
    }

    @Override
    public Boolean addDoc(Doctor doctor) {
        Integer i = doctorMapper.addDoc(doctor);
        return i>=0;
    }

    @Override
    public List<Doctor> getDocByName(String name) {
        return doctorMapper.getDocByName(name);
    }

    @Override
    public ArrayList<Doctor> searchDocByName(String specialty, String docName) {
        return doctorMapper.searchDocByName(specialty, docName);
    }

}
